package com.nust.fragment;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.bmob.im.ui.SplashActivity;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.nust.main.AboutDialogActivity;
import com.nust.main.Help;
import com.nust.main.R;

public class Util {
	public static String getText(String text) {
		int length = text.length();
		if (length < 13) {
			return text;
		} else if (length > 24) {
			text = text.substring(0, 24);
		}
		String textHeadString = text.substring(0, 13);
		text = text.replace(textHeadString, textHeadString + "\n");
		return text;
	}

	public static SlidingMenu initSlidingMenu(Activity context) {
		SlidingMenu slidingMenu = new SlidingMenu(context);
		slidingMenu.setMode(SlidingMenu.LEFT);
		slidingMenu.setBehindOffsetRes(R.dimen.sliding_menu_offset);
		slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
		slidingMenu.attachToActivity(context, SlidingMenu.SLIDING_CONTENT);
		slidingMenu.setMenu(R.layout.menu_left);
		slidingMenu.setShadowDrawable(R.drawable.shadow);
		slidingMenu.setShadowWidth(30);
		return slidingMenu;
	}

	public static void initActionButton(final Activity activity,
			final SlidingMenu slidingMenu) {
		slidingMenu.getMenu().findViewById(R.id.shou_login)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						activity.startActivity(new Intent(activity,
								SplashActivity.class));
					}
				});

		slidingMenu.getMenu().findViewById(R.id.help)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						activity.startActivity(new Intent(activity,
								Help.class));
					}
				});

		slidingMenu.getMenu().findViewById(R.id.about)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub

						activity.startActivity(new Intent(activity,
								AboutDialogActivity.class));
					}
		});
	}

}
